<template>
  <div>
    <form @submit.prevent="fn">
      <label >姓名：</label>
      <input type="text" v-model="name"><br><br>

      <label>年龄：</label>
      <input type="number" v-model="age"><br><br>

      <label>身高：</label>
      <input type="number" v-model="height" step="0.01">(米)<br><br>

      <label>体重：</label>
      <input type="number" v-model="weight" step="0.01">(公斤)<br><br>

      <label>病史：</label>
      <input type="text" v-model="medical"><br><br>

      <button>诊断</button>
    </form>

    <p v-show="flag">患者 {{name}} 的诊断结果：{{res}}</p>
  </div>
</template>

<script>
export default {
  data () {
    return {
      name:'',
      age:0,
      height:0,
      weight:0,
      medical:'',
      BMI:'',
      res:'',
      flag:false
    }
  },
  methods: {
    fn(){
      this.flag = true
      this.BMI = (this.weight/(this.height*this.height));
      // console.log(this.BMI)
      if(this.BMI<18.5){
        this.res='过轻'

      }else if(this.BMI>24.9){
        this.res='过重'
      }else{
        this.res='健康'
      }   
    }

  }
}
</script>

